package huawei.js2025;

import java.util.*;
import java.util.stream.Collectors;

/**
 * N个选手比赛前三名、比赛
 */
public class Question38 {

    public static class Person implements Comparable<Person> {
        private int no;
        private int totalScore = 0;
        private List<Integer> scores = new ArrayList<>();

        public Person(int no) {
            this.no = no;
            this.scores = new ArrayList<>();
        }

        public void sortScores() {
            scores.sort(Integer::compareTo);
        }

        public void addScore(int score) {
            totalScore += score;
            scores.add(score);
        }

        @Override
        public int compareTo(Person o) {
            if (o.totalScore - totalScore != 0) {
                return o.totalScore - totalScore;
            }

            for (int i = scores.size() - 1; i >= 0; i--) {
                if (scores.get(i) - o.scores.get(i) == 0) continue;
                return o.scores.get(i) - scores.get(i);
            }
            return 0;
        }
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        List<Integer> info = Arrays.stream(sc.nextLine().split(",")).map(String::trim).map(Integer::parseInt).collect(Collectors.toList());

        List<Person> persons = new ArrayList<>();
        for (int i = 0; i < info.get(1); i++) {
            persons.add(new Person(i + 1));
        }

        if (info.get(1) < 3) {
            System.out.println(-1);
            return;
        }

        for (int i = 0; i < info.get(0); i++) {
            List<Integer> list = Arrays.stream(sc.nextLine().split(",")).map(String::trim).map(Integer::parseInt).collect(Collectors.toList());
            for (int j = 0; j < persons.size(); j++) {
                Person person = persons.get(j);
                person.addScore(list.get(j));
            }
        }

        for (Person person : persons) {
            person.sortScores();
        }

        Collections.sort(persons);
        for (int i = 0; i < 3; i++) {
            if (i < 2) {
                System.out.print(persons.get(i).no + ",");
            } else {
                System.out.println(persons.get(i).no);
            }
        }
        System.out.println(persons);
    }
}
